package com.atguigu.ssyx.acl.controller;

import com.atguigu.ssyx.acl.service.RoleService;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.acl.Role;
import com.atguigu.ssyx.vo.acl.RoleQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杨林
 * @create 2023-07-06 9:56 星期四
 * description:角色管理
 */
@CrossOrigin  //跨域
@RestController
@RequestMapping("/admin/acl/role")
@Api(tags = "用户管理")
@Slf4j   //日志
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation(value = "获取角色分页列表")
    @GetMapping("/{page}/{limit}")
    public Result index(
            @ApiParam(name = "page",value = "当前页码",required = true) @PathVariable("page") Long page,
            @ApiParam(name = "limit",value = "每页条数",required = true) @PathVariable("limit") Long limit,
            @ApiParam(name = "roleQueryVo",value = "查询对象",required = false)  RoleQueryVo roleQueryVo
            ){
        IPage<Role> pageModel = roleService.selectPage(roleQueryVo,page,limit);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "获取角色")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id){
        Role role = roleService.getById(id);
        return Result.ok(role);
    }

    @ApiOperation(value = "新增角色")
    @PostMapping("/save")
    public Result save(@RequestBody Role role){
        roleService.save(role);
        return Result.ok();
    }

    @ApiOperation(value = "删除角色")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") Long id){
        roleService.removeById(id);   //逻辑删除
        return Result.ok();
    }

    @ApiOperation(value = "修改角色")
    @PutMapping("/update")
    public Result update(@RequestBody Role role){
        roleService.updateById(role);
        return Result.ok();
    }

    @ApiOperation(value = "根据id批量删除角色")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> ids){
        roleService.removeByIds(ids);
        return Result.ok();
    }
}
